<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="编号" prop="number">
        <el-input  v-model="form.numberNum" disabled style="width: 280px;"/>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-select

          v-model="form.projectName"
          placeholder="请选择" clearable
          style="width: 280px;"
          :disabled="title!='添加付款申请'">
          <el-option
            v-for="item in projectNameList"
            :key="item.projectName"
            :label="item.projectName"
            :value="item.projectName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="付款主体" prop="payUnit">
        <el-input v-model="form.payUnit"style="width: 280px;" :disabled='isdisabled' placeholder="请输入付款单位" />
      </el-form-item>
      <el-form-item label="付款金额(元)" prop="payTotal" >
        <el-input v-model="form.payTotal"
                  style="width: 280px;"
                  @input="form.payTotal=form.payTotal.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/,'$1')"
                  :disabled='isdisabled' placeholder="请输入付款金额" />
      </el-form-item>
      <el-form-item label="付款方式" prop="payWay">
        <el-select v-model="form.payWay"
                   style="width: 280px;"
                   placeholder="请选择付款方式" :disabled='isdisabled'>
          <el-option
            v-for="dict in dict.type.pay_way"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="付款日期" prop="payDate">
        <el-date-picker
          clearable
          v-model="form.payDate"
          type="date"
          style="width: 280px;"
          value-format="yyyy-MM-dd"
          placeholder="请选择付款日期"
          :disabled="isdisabled"
          default-time="00:00:00"
          format="yyyy-MM-dd"
          @change="dateChanged"
          :picker-options="pickerOption"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="收款人全称" prop="payeeName" >
        <el-input v-model="form.payeeName" style="width: 280px;" :disabled='isdisabled' placeholder="请输入收款人全称" />
      </el-form-item>
      <el-form-item label="银行账号" prop="bankAccount">
        <el-input v-model="form.bankAccount" style="width: 280px;" :disabled='isdisabled' placeholder="请输入银行账号" />
      </el-form-item>
      <el-form-item label="开户行" prop="bank">
        <el-input v-model="form.bank" style="width: 280px;" :disabled='isdisabled' placeholder="请输入开户行" />
      </el-form-item>
      <el-form-item label="申请事由" prop="applyReason" class="businessReason">
        <el-input :disabled='isdisabled' v-model="form.applyReason" type="textarea" placeholder="请输入内容" style="width: 100%"/>
      </el-form-item>
      <el-form-item label="工程类合同:" v-if="!(isdisabled&&!form.engineeringContract)">
        <file-upload v-model="form.engineeringContract"  :isDisabled='isdisabled'/>
      </el-form-item>
      <el-form-item label="行政类材料:" v-if="!(isdisabled&&!form.administrationContract)" >
        <file-upload v-model="form.administrationContract":isDisabled='isdisabled'/>
      </el-form-item>
    </el-form>
    <div
      v-show="parentTaskId===null&&confirmVisible"
      class="dialog-footer"
      style="text-align:center"
    >
      <el-button :loading="buttonLoading" size="small" type="info" @click="submitCallback">关闭</el-button>
      <el-button :loading="buttonLoading" size="small" type="primary" @click="submitForm">提交</el-button>
    </div>
    <div
      v-show="parentTaskId==null&&!confirmVisible"
      class="dialog-footer"
      style="text-align:right"
    >
      <el-button :loading="buttonLoading" size="small" type="info" @click="submitCallback">关闭</el-button>
    </div>
    <!-- 工作流开始 -->
    <verify
      ref="verifyRef"
      :taskId="taskId"
      @submitCallback="submitCallback"
      :componentName="componentName"
      :taskVariables="taskVariables"
      :sendMessage="sendMessage"
    ></verify>
  </div>
</template>

<script>
import { getPurchaesPayment } from "@/api/oa/purchaesPayment";
import verify from "@/components/Process/Verify";
import { parseTime } from "@/utils/ruoyi";
export default {
  dicts: ["act_status", "pay_way"],
  name: "PurchaesPaymentForm",
  components: {
    verify
  },
  props: {
    componentName: "采购付款申请",
    title: "",
    businessKey: String, // 业务唯一标识
    parentTaskId: String, // 父级任务id
    taskId: String, // 任务id
    confirmVisible: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      isdisabled: true,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ]
      },
      // 出差日期的可选范围
      pickerOption: {
        disabledDate: time => {
          return time.getTime() <= Date.now() - 8.64e7;
        }
      },
      taskVariables: undefined,
      //消息提醒
      sendMessage: {},
      processKey: "oa_purchase_payment",
      projectNameList: []
    };
  },
  watch: {
    businessKey: {
      immediate: true, // 很重要！！！
      handler(newVal) {
        if (newVal) {
          this.getById();
        }
      }
    }
  },
  methods: {
    submitCallback() {
      this.$emit("closeForm");
    },
    async getById() {
      const { data } = await getPurchaesPayment(this.businessKey);
      this.form = data;
      if (data.actBusinessStatus.createTime) {
        this.form.numberNum =
          this.processKey +
          "@" +
          parseTime(data.actBusinessStatus.createTime, "{y}{m}{d}{h}{i}{s}");
      }
    },
    /** 提交按钮 */
    submitForm() {
      getPurchaesPayment(this.businessKey).then(response => {
        this.taskVariables = {
          entity: response.data
        };

        this.sendMessage = {
          title: "采购付款申请审批提醒",
          messageContent:
            this.$store.state.user.nickName + "审批通过了采购付款申请"
        };
      });
      this.$refs.verifyRef.visible = true;
      this.$refs.verifyRef.reset();
    },
    /*日期范围控件选择完毕*/
    dateChanged() {
      if (this.form.startDate != null && this.form.endDate != null) {
        let val = dayjs(this.form.endDate).diff(
          dayjs(this.form.startDate),
          "days"
        );
        this.form.duration = val < 0 ? val : val + 1;
      }
    }
  }
};
</script>
<style scoped>
/* 设置滚动条宽度和高度 */
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 8px; /* 横向滚动条 */
  height: 8px; /* 纵向滚动条 必写 */
}
/* 设置滚动条样式 */
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #dde;
  border-radius: 3px;
}
#selectForm >>> .el-form-item__label {
  font-size: 12px;
}
::v-deep .bjsm .el-form-item__content {
  width: calc(100% - 130px) !important;
}
</style>
